﻿Imports System.Data.OleDb
Public Class addnew
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim newFileName As String
        newFileName = Guid.NewGuid().ToString() & getSuffix(I1.FileName)
        If I1.HasFile Then
            I1.SaveAs(Server.MapPath("images") & "/" & newFileName)
        End If



        Dim sql As String = "INSERT INTO [crick] (schedule,results,relatedwebsites,gallery) VALUES (@f1,@f2,@f3,@f4)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("maniaConnectionstring").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", t1.Text)
        cmd.Parameters.AddWithValue("@f2", t2.Text)
        cmd.Parameters.AddWithValue("@f3", t3.Text)

        cmd.Parameters.AddWithValue("@f4", "images/" & newFileName)

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("list.aspx")
    End Sub
    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function
End Class